<template>
  <div class="addNodePool">
    <el-form ref="form" :model="form" :rules="rules" label-width="100px">
      <el-form-item label="排序" prop="sort">
        <el-input v-model.number="form.sort" type="number" placeholder="请输入排序" />
      </el-form-item>
      <el-form-item label="父类id" prop="parentId">
        <el-input v-model="form.parentId" disabled placeholder="请输入父类id" />
      </el-form-item>
      <el-form-item label="级别" prop="level">
        <el-input v-model="form.level" disabled placeholder="请输入级别" />
      </el-form-item>
      <el-form-item label="节点池名称" prop="nodeName">
        <el-input v-model="form.nodeName" placeholder="请输入节点池名称" />
      </el-form-item>
      <el-form-item label="节点池类型" prop="nodeType">
        <el-select clearable v-model="form.nodeType" placeholder="请选择线路类型">
          <el-option v-for="(option, index) in idcList" :key="index" :value="option.dictValue"
            :label="option.dictLabel" />
        </el-select>
      </el-form-item>
    </el-form>
    <div class="dialog-footer">
      <el-button type="primary" @click="submitForm">确 定</el-button>
      <el-button @click="cancel">取 消</el-button>
    </div>
  </div>
</template>

<script>
import { getDicts as getDicts } from '@/api/system/dict/data'

export default {
  name: "AddNodePool",
  props: {
    fromData: {
      type: Object,
      default: {}
    }
  },
  data() {
    return {
      // 表单校验
      rules: {
        sort: [{ required: true, message: "排序不能为空", trigger: "blur" }],
        nodeName: [{ required: true, message: "节点池名称不能为空", trigger: "blur" }],
        nodeType: [{ required: true, message: "节点池类型不能为空", trigger: "blur" }],
      },
      idcList: [],
      form: {
        id: '',
        subType: '',    // 0 不存在取消
        sort: '',
        parentId: '',
        level: '',
        nodeName: '',
        nodeType: ''
      },
    }
  },
  computed: {
  },
  filters: {
  },
  created() {
    this.form.editType = this.fromData.editType || '';
    this.form.id = this.fromData.id || '';
    this.form.sort = this.fromData.sort || '';
    this.form.parentId = this.fromData.parentId || '';
    this.form.level = this.fromData.level || '';
    this.form.nodeName = this.fromData.nodeName || '';
    this.form.nodeType = this.fromData.nodeType || '';

    getDicts('line_type').then(res => {
      if (res.code == 200) {
        this.idcList = res.data || [];
      }
    })
  },
  methods: {
    handleTabChange(tabIndex) {
      // return false;
    },
    // 取消按钮
    cancel() {
      this.form.subType = '';
      this.$emit('subPoolDate', this.form)
    },
    // 表单重置
    reset() {
      this.form = {
        id: '',
        subType: '',
        sort: '',
        parentId: '',
        level: '',
        nodeName: '',
        nodeType: ''
      };
      this.resetForm("form");
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          this.form.subType = 1;
          this.$emit('subPoolDate', this.form)
        }
      });
    },
  }
};
</script>
<style scoped>
.dialog-footer {
  text-align: right;
}
</style>
